package com.huonan.jb.tools.esuse.export.type;


import cn.hutool.setting.dialect.Props;
import com.huonan.jb.tools.esuse.dto.EsHitsInfo;
import com.huonan.jb.tools.esuse.export.content.ExtractFields;
import com.huonan.jb.tools.esuse.export.strategy.ExportFileStrategy;
import com.huonan.jb.tools.esuse.export.strategy.ExportSlayer;
import com.huonan.jb.tools.esuse.export.utils.EsUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @Description 写入文件
 * @Author lxp
 * @Date 2023/2/6 上午11:01
 * @Version V1.0
 **/
@Slf4j
public class ExportCsvFile extends ExportFile implements ExportFileStrategy {

    public void exportDataToFile(Props props, EsHitsInfo dataResult) {
        ExtractFields extractFields = new ExtractFields();
        ExportSlayer textFile = new ExportSlayer();
        String subFile;
        List<String> fieldsList;
        String filePath;
        //导出csv文件
        subFile = "csv";
        filePath = getFilePah(props, subFile);
        fieldsList = extractFields.extractCsvFields(dataResult.getHits(), false);
        textFile.changeStrategy(new ExportCsvFile());
        textFile.goToExport(fieldsList, filePath);
    }
    private static String getFilePah(Props props, String subFile) {
        return EsUtils.getFilePath(props, subFile);
    }

}
